package com.manuelvs.bobbysadventure;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.SpriteBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import org.anddev.andengine.util.HorizontalAlign;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;


public class tutorial2 extends BaseGameActivity {
	private Camera mCamera;
    
    private BitmapTextureAtlas mBitmapTextureAtlasFondo;
    private TextureRegion Fondo;
    
    private Scene mMainScene;
    
    private BitmapTextureAtlas mFontTexture;
    private Font mFont;
    
	@Override
	public Engine onLoadEngine() 
	{
		mCamera = new Camera(0, 0, 480, 320);
		return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE,new RatioResolutionPolicy(480, 320), mCamera));
	}

	@Override
	public void onLoadResources() {
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		this.mBitmapTextureAtlasFondo = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR);
        this.Fondo = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlasFondo, this, "fondo.png", 0, 0);
        this.mEngine.getTextureManager().loadTextures(this.mBitmapTextureAtlasFondo);
        
        this.mFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

        this.mFont = new Font(this.mFontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 16, true, Color.BLACK);

        this.mEngine.getTextureManager().loadTexture(this.mFontTexture);
        this.mEngine.getFontManager().loadFont(mFont);
	}

	@Override
	public Scene onLoadScene() {
		
	    mMainScene = new Scene();
	    
		SpriteBackground bg = new SpriteBackground(new Sprite(0, 0, Fondo));
		mMainScene.setBackground(bg);
		
		final Text boton16 = new Text(0, 0, this.mFont, getText(R.string.stringboton1).toString() + "\n" + getText(R.string.stringboton2).toString()
				+ "\n" + getText(R.string.stringboton3).toString() 
				+ "\n" + getText(R.string.stringboton4).toString() 
				+ "\n" + getText(R.string.stringboton5).toString()
				+ "\n" + getText(R.string.stringboton6), HorizontalAlign.LEFT);
		mMainScene.attachChild(boton16);
		
		
		final Text boton79 = new Text(163, 170, this.mFont, getText(R.string.stringboton7).toString()
				+ "\n" + getText(R.string.stringboton8).toString()
				+ "\n" + getText(R.string.stringboton9).toString(), HorizontalAlign.LEFT);
		mMainScene.attachChild(boton79);
	    return mMainScene;
	}

	@Override
	public void onLoadComplete() {}
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.more_apps:
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=ManuelVS"));
        	startActivity(browserIntent);
            return true;
        case R.id.configuration:
        	final Intent configuration = new Intent(tutorial2.this, configuration.class);
        	startActivity(configuration);
            return true;
        }
        return false;
        
    }
}